﻿using System;
using Fly.Data;
using FlyWebFrame.Model;

namespace FlyWebFrame.Action
{
    public class schedule : homeaction
    {
        public int courseId;
        public string start_time;
        public string location;
        public string cost;
        public string certs;
        public string lecturer;
        public string language;
        public string level;
        public string code;
        public string conditions;
        public int duration;
        public string functions;
        public string skills;
        public string descriptions;
        public string topics;
        public string attendant;
        public string benefit;
        public string title;

        public dynamic others;

        public override void Treat()
        {
            Int32.TryParse(GetParameter(1), out courseId);
            current_link = "courses/" + other_lang + "/" + courseId;
            content_right = "/html/home/schedule_course_detail.html";

            this.renderLeftNav(19);

            Schedule schedule = new Schedule();
            schedule.id = courseId;
            if (schedule.Instance().Status)
            {
                Courses course = new Courses();
                course.id = schedule.courseId;
                course.Instance();

                code = course.code;
                if (schedule.dayStart == 0 && schedule.monthStart != 0)
                {
                    start_time = "Tháng "+schedule.monthStart;
                }
                else if (schedule.monthStart == 0)
                {
                    start_time = "TBA";
                }
                else
                {
                    start_time = schedule.dayStart.ToString() + "/" + schedule.monthStart;
                }
                location = schedule.location;
                cost = schedule.cost;
                certs = schedule.certs;
                language = schedule.language;
                lecturer = schedule.lecturer;
                conditions = course.conditions;
                duration = course.duration;
                functions = course.functions;
                skills = course.skills;
                descriptions = course.descriptions;
                topics = course.topics;
                attendant = course.attendant;
                benefit = course.benefit;
                title = course.title;

                if (level == "1")
                {
                    level = "Tổng quan";
                }
                else if (level == "2")
                {
                    level = "Nền tảng";
                }
                else if (level == "3") 
                {
                    level = "Nâng cao";
                }
                else if (level == "4")
                {
                    level = "Chuyên ngành";
                }

                if (conditions == null || conditions == "")
                {
                    conditions = "Không";
                }
                else
                {
                    Result r = course.GetByIds(conditions);
                    conditions = "";
                    for (int i = 0; i < r.Data.Length; i++)
                    {
                        conditions += r.Data[i].code + " " + r.Data[i].title + "<br />";
                    }
                }

                others = schedule.Get().Data;
                dynamic courses = course.Get().Data;
                foreach (Schedule s in others)
                {
                    foreach (Courses c in courses)
                    {
                        if (s.courseId == c.id)
                        {
                            s.title = c.title;
                        }
                    }
                }

                big_title = "Lịch khai giảng";
                current_title = course.title;
            }
        }
    }
}